<?php
defined('OPEN_LIB_PATH') || define('OPEN_LIB_PATH', '/opt/op/OpenLib');

require_once OPEN_LIB_PATH . '/stat/lib/OaLog.php';

class OaLogic
{
    private static $_errno = 0;
    private static $_error = ''; 
    
    public static function setError($errno, $error = '')
    {
        self::$_errno = $errno;
        self::$_error = $error;
        return true;
    }
    
    public static function getErrorNo()
    {
        return self::$_errno;
    }
    
    public static function getErrorMessage()
    {
        return self::$_error;
    }
    
    public static function getLogger()
    {
        $logger = Log::factory('composite');
        $conf = array(
            'lineFormat' => '[%1$s] [%3$s] %5$s(%6$s): %4$s',
            'timeFormat' => '%Y-%m-%d %H:%M:%S',
            'mode' => '0666'
        );
        $loggerDisplay = Log::factory('display', '', '', $conf, PEAR_LOG_ERR);
        $loggerFile = new OaLog('oa_logic', '', $conf, PEAR_LOG_INFO);
        if (__OA_ENV == 'DEV') {
            $logger->addChild($loggerDisplay);
            $logger->addChild($loggerFile);
        } else if (__OA_ENV == 'TEST') {
            $logger->addChild($loggerDisplay);
            $logger->addChild($loggerFile);
        } else {
            $logger->addChild($loggerFile);
        }
        return $logger;
    }
}
